class myVue {
    constructor (options) {
        //通过属性保存选项数据
        this.$options = options;
        this.$el = typeof options.el === 'string' ? document.querySelector(options.el) : options.el;
        this.$data = options.data;
        //将方法注入到Vue实例
        this.$options.methods && Object.keys(this.$options.methods).forEach(method => {
            this[method] = this.$options.methods[method];
        });
        //把data中的成员转换为getter和setter,注入到Vue实例中
        this._proxyData(this.$data);
        //调用observer监听数据变化
        new observer(this.$data);
        //调用compiler编译模板、解析指令/插值表达式
        new compiler(this);
    }

    _proxyData (data) {
        Object.keys(data).forEach(key => {
            Object.defineProperty(this, key, {
                enumerable: true,
                configurable: true,
                get () {
                    return data[key];
                },
                set (newValue) {
                    if (newValue === data[key]) return;
                    data[key] = newValue;
                }
            });
        });
    }
};